
$(document).ready(function() {
	$('#dataForm').initFormDictSelect();

	validateRule();
});



$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : window.API_SERVER_URL + "smm/supplier/save",
		data : $('#dataForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("保存失败");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i>";
	$("#dataForm").validate({
		rules : {
			name : {
				required : true
			},
            type : {
				required : true
			},
			level : {
				required : true
			},
            contacts : {
				required : true
			},
            contactsMobile : {
				required : true
			},
            contactsEmail : {
				required : true,
				email : true
			},
            email : {
                required : false,
                email : true
            },
		},
		messages : {

			name : {
				required : icon + "请输入供应商名称"
			},
            type : {
				required : icon + "请选择类型"
			},
            level : {
				required : icon + "请选择级别"
			},
            contacts : {
				required : icon + "请输入联系人名称"
			},
            contactsMobile : {
                required : icon + "请输入联系人电话"
            },
            contactsEmail : {
                required : icon + "请输入联系人邮箱",
				email:icon + "请输入正确联系人邮箱"

            },
			email : icon + "请输入正确邮箱",
		}
	})
}


